package com.yanqu.road.server.cmd.activity.summergames;

import com.yanqu.road.entity.activity.summergames.SummerGamesConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SummerGamesProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.summergames.SummerGamesModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.summergames.SummerGamesActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_SUMMER_GAMES_TIP_READ, desc = "提醒已读")
public class SummerGamesExchangeTipReadCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        SummerGamesConfig config = SummerGamesActivityMgr.getSummerGamesConfig();
        // 没有活动
        if (config == null || !ActivityMgr.activityInTimeAndShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        SummerGamesProto.SummerGamesExchangeTipReadReqMsg reqMsg = SummerGamesProto.SummerGamesExchangeTipReadReqMsg.parseFrom(packet.getBytes());

        ret = player.getModule(SummerGamesModule.class).readTip(reqMsg.getIdList());

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_SUMMER_GAMES_TIP_READ, SummerGamesProto.SummerGamesExchangeTipReadRespMsg.newBuilder().setRet(ret));
        }
    }
}
